﻿package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.Cargo;
import com.edward.model.DT_Cargo;


public class DT_CargoManager extends HibernateDaoSupport {
	


	public void addDT_Cargo(DT_Cargo dt_Cargo) {
		
		getHibernateTemplate().save(dt_Cargo);
	}
	
	@SuppressWarnings("unchecked")
	public PagerModel pagerDTCargo(int start,int limit,int id) {
		List <DT_Cargo>list = getHibernateTemplate().find("from DT_Cargo d where DTCargo_ID = " + id );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <DT_Cargo>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	public void updateDT_Cargo(DT_Cargo dt_Cargo) {
		
		getHibernateTemplate().update(dt_Cargo);
	}
	public DT_Cargo getDT_Cargo(int id){
		DT_Cargo d =(DT_Cargo)getHibernateTemplate().get(DT_Cargo.class, id);
		return d;
	}

	public void deleteDT_Cargo(int id){
		
		getHibernateTemplate().delete(getDT_Cargo(id));
	}
	
	@SuppressWarnings("unchecked")
	public boolean check(int id){
		List <DT_Cargo>listd = getHibernateTemplate().find("from DT_Cargo d where CARGO_ID = " + id );
		List <Cargo>listc = getHibernateTemplate().find("from Cargo c where c.id = " + id  + " and c.sign is not null"  );
		if(listd.size() == 1 && listc.isEmpty()){
			return true;
		}else{
			return false;
		}
		
	}
	
	@SuppressWarnings("unchecked")
	public boolean checkCargo(int id){
		List <DT_Cargo>listd = getHibernateTemplate().find("from DT_Cargo d where CARGO_ID = " + id );
		if(listd.size() == 0){
			return true;
		}
		return false;
		
	}
	

	



}



